
module.exports = {
    uuid: function (t, e) {
        var n, o, i, a;
        if (n = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),
            a = [], o = void 0, e = e || n.length, t)
            for (o = 0; o < t;) a[o] = n[0 | Math.random() * e],
                o++;
        else
            for (i = void 0, a[8] = a[13] = a[18] = a[23] = "-", a[14] = "4", o = 0; o < 36;) a[o] || (i = 0 | 16 * Math.random(),
                a[o] = n[19 === o ? 3 & i | 8 : i]), o++;
        return a.join("");
    },
    random: function (t) {
        var e, n = !0;
        if (t) {
            for (; n;)
                if ((e = Math.random()) > .1) return n = !1, Math.floor(e * Math.pow(10, t));
        } else
            for (; n;)
                if ((e = Math.random()) > .1) return n = !1, Math.floor(e * Math.pow(10, 5));
    },
    hex_sha256: function (t) {
        var e, n, o, i = function (t, e) {
                return e >>> t | e << 32 - t;
            },
            a = function (t, e, n) {
                return t & e ^ ~t & n;
            },
            s = function (t, e, n) {
                return t & e ^ t & n ^ e & n;
            },
            c = function (t) {
                return i(2, t) ^ i(13, t) ^ i(22, t);
            },
            r = function (t) {
                return i(6, t) ^ i(11, t) ^ i(25, t);
            },
            l = function (t, e) {
                return t[15 & e] += function (t) {
                    return i(17, t) ^ i(19, t) ^ t >>> 10;
                }(t[e + 14 & 15]) + t[e + 9 & 15] + function (t) {
                    return i(7, t) ^ i(18, t) ^ t >>> 3;
                }(t[e + 1 & 15]);
            },
            d = new Array(1116352408, 1899447441, 3049323471, 3921009573, 961987163, 1508970993, 2453635748, 2870763221, 3624381080, 310598401, 607225278, 1426881987, 1925078388, 2162078206, 2614888103, 3248222580, 3835390401, 4022224774, 264347078, 604807628, 770255983, 1249150122, 1555081692, 1996064986, 2554220882, 2821834349, 2952996808, 3210313671, 3336571891, 3584528711, 113926993, 338241895, 666307205, 773529912, 1294757372, 1396182291, 1695183700, 1986661051, 2177026350, 2456956037, 2730485921, 2820302411, 3259730800, 3345764771, 3516065817, 3600352804, 4094571909, 275423344, 430227734, 506948616, 659060556, 883997877, 958139571, 1322822218, 1537002063, 1747873779, 1955562222, 2024104815, 2227730452, 2361852424, 2428436474, 2756734187, 3204031479, 3329325298),
            h = function (t, e) {
                var n = (65535 & t) + (65535 & e);
                return (t >> 16) + (e >> 16) + (n >> 16) << 16 | 65535 & n;
            },
            u = function () {
                var t, n, i, u, g, p, f, m, S, v, y = new Array(16);
                t = e[0], n = e[1], i = e[2], u = e[3], g = e[4], p = e[5], f = e[6], m = e[7];
                for (var w = 0; w < 16; w++) y[w] = o[3 + (w << 2)] | o[2 + (w << 2)] << 8 | o[1 + (w << 2)] << 16 | o[w << 2] << 24;
                for (var b = 0; b < 64; b++) S = m + r(g) + a(g, p, f) + d[b], S += b < 16 ? y[b] : l(y, b),
                    v = c(t) + s(t, n, i), m = f, f = p, p = g, g = h(u, S), u = i, i = n, n = t, t = h(S, v);
                e[0] += t, e[1] += n, e[2] += i, e[3] += u, e[4] += g, e[5] += p, e[6] += f, e[7] += m;
            };
        return e = new Array(8), n = new Array(2), o = new Array(64), n[0] = n[1] = 0, e[0] = 1779033703,
            e[1] = 3144134277, e[2] = 1013904242, e[3] = 2773480762, e[4] = 1359893119, e[5] = 2600822924,
            e[6] = 528734635, e[7] = 1541459225,
            function (t, e) {
                var i, a, s = 0;
                a = n[0] >> 3 & 63;
                var c = 63 & e;
                for ((n[0] += e << 3) < e << 3 && n[1]++, n[1] += e >> 29, i = 0; i + 63 < e; i += 64) {
                    for (var r = a; r < 64; r++) o[r] = t.charCodeAt(s++);
                    u(), a = 0;
                }
                for (r = 0; r < c; r++) o[r] = t.charCodeAt(s++);
            }(t, t.length),
            function () {
                var t = n[0] >> 3 & 63;
                if (o[t++] = 128, t <= 56)
                    for (var e = t; e < 56; e++) o[e] = 0;
                else {
                    for (e = t; e < 64; e++) o[e] = 0;
                    for (u(), e = 0; e < 56; e++) o[e] = 0;
                }
                o[56] = n[1] >>> 24 & 255, o[57] = n[1] >>> 16 & 255, o[58] = n[1] >>> 8 & 255,
                    o[59] = 255 & n[1], o[60] = n[0] >>> 24 & 255, o[61] = n[0] >>> 16 & 255, o[62] = n[0] >>> 8 & 255,
                    o[63] = 255 & n[0], u();
            }(),
            function () {
                for (var t = new String(), n = 0; n < 8; n++)
                    for (var o = 28; o >= 0; o -= 4) t += "0123456789abcdef".charAt(e[n] >>> o & 15);
                return t;
            }();
    },
    base64_decode: function (t) {
        var e, n, o, i, a, s, c = "",
            r = 0,
            l = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
        for (t = t.replace(/[^A-Za-z0-9\+\/\=]/g, ""); r < t.length;) e = l.indexOf(t.charAt(r++)) << 2 | (i = l.indexOf(t.charAt(r++))) >> 4,
            n = (15 & i) << 4 | (a = l.indexOf(t.charAt(r++))) >> 2, o = (3 & a) << 6 | (s = l.indexOf(t.charAt(r++))),
            c += String.fromCharCode(e), 64 != a && (c += String.fromCharCode(n)), 64 != s && (c += String.fromCharCode(o));
        return c = function (t) {
            var e, n, o, i = "",
                a = 0;
            for (e = n = o = 0; a < t.length;)(e = t.charCodeAt(a)) < 128 ? (i += String.fromCharCode(e),
                a++) : e > 191 && e < 224 ? (n = t.charCodeAt(a + 1), i += String.fromCharCode((31 & e) << 6 | 63 & n),
                a += 2) : (n = t.charCodeAt(a + 1), o = t.charCodeAt(a + 2), i += String.fromCharCode((15 & e) << 12 | (63 & n) << 6 | 63 & o),
                a += 3);
            return i;
        }(c);
    },
    base64_encode: function (t) {
        var e, n, o, i, a, s, c, r = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
            l = "",
            d = 0;
        for (t = function (t) {
                t = t.replace(/\r\n/g, "\n");
                for (var e = "", n = 0; n < t.length; n++) {
                    var o = t.charCodeAt(n);
                    o < 128 ? e += String.fromCharCode(o) : o > 127 && o < 2048 ? (e += String.fromCharCode(o >> 6 | 192),
                        e += String.fromCharCode(63 & o | 128)) : (e += String.fromCharCode(o >> 12 | 224),
                        e += String.fromCharCode(o >> 6 & 63 | 128), e += String.fromCharCode(63 & o | 128));
                }
                return e;
            }(t); d < t.length;) i = (e = t.charCodeAt(d++)) >> 2, a = (3 & e) << 4 | (n = t.charCodeAt(d++)) >> 4,
            s = (15 & n) << 2 | (o = t.charCodeAt(d++)) >> 6, c = 63 & o, isNaN(n) ? s = c = 64 : isNaN(o) && (c = 64),
            l = l + r.charAt(i) + r.charAt(a) + r.charAt(s) + r.charAt(c);
        return l;
    },
    hex_sha1: function (t) {
        var e = function (t, e) {
                return t << e | t >>> 32 - e;
            },
            n = function (t, e) {
                var n = (65535 & t) + (65535 & e);
                return (t >> 16) + (e >> 16) + (n >> 16) << 16 | 65535 & n;
            },
            o = function (t, e, n, o) {
                return t < 20 ? e & n | ~e & o : t < 40 ? e ^ n ^ o : t < 60 ? e & n | e & o | n & o : e ^ n ^ o;
            },
            i = function (t) {
                return t < 20 ? 1518500249 : t < 40 ? 1859775393 : t < 60 ? -1894007588 : -899497514;
            };
        return function (t) {
            for (var e = "0123456789abcdef", n = "", o = 0; o < 4 * t.length; o++) n += e.charAt(t[o >> 2] >> 8 * (3 - o % 4) + 4 & 15) + e.charAt(t[o >> 2] >> 8 * (3 - o % 4) & 15);
            return n;
        }(function (t, a) {
            t[a >> 5] |= 128 << 24 - a % 32, t[15 + (a + 64 >> 9 << 4)] = a;
            for (var s = Array(80), c = 1732584193, r = -271733879, l = -1732584194, d = 271733878, h = -1009589776, u = 0; u < t.length; u += 16) {
                for (var g = c, p = r, f = l, m = d, S = h, v = 0; v < 80; v++) {
                    s[v] = v < 16 ? t[u + v] : e(s[v - 3] ^ s[v - 8] ^ s[v - 14] ^ s[v - 16], 1);
                    var y = n(n(e(c, 5), o(v, r, l, d)), n(n(h, s[v]), i(v)));
                    h = d, d = l, l = e(r, 30), r = c, c = y;
                }
                c = n(c, g), r = n(r, p), l = n(l, f), d = n(d, m), h = n(h, S);
            }
            return Array(c, r, l, d, h);
        }(function (t) {
            for (var e = Array(), n = 0; n < 8 * t.length; n += 8) e[n >> 5] |= (255 & t.charCodeAt(n / 8)) << 24 - n % 32;
            return e;
        }(t), 8 * t.length));
    },
    hex_md5: function (t) {
        var e = function (t, e, n, o, i, a) {
                return s(c(s(s(e, t), s(o, a)), i), n);
            },
            n = function (t, n, o, i, a, s, c) {
                return e(n & o | ~n & i, t, n, a, s, c);
            },
            o = function (t, n, o, i, a, s, c) {
                return e(n & i | o & ~i, t, n, a, s, c);
            },
            i = function (t, n, o, i, a, s, c) {
                return e(n ^ o ^ i, t, n, a, s, c);
            },
            a = function (t, n, o, i, a, s, c) {
                return e(o ^ (n | ~i), t, n, a, s, c);
            },
            s = (e = function (t, e, n, o, i, a) {
                return s(c(s(s(e, t), s(o, a)), i), n);
            }, function (t, e) {
                var n = (65535 & t) + (65535 & e);
                return (t >> 16) + (e >> 16) + (n >> 16) << 16 | 65535 & n;
            }),
            c = function (t, e) {
                return t << e | t >>> 32 - e;
            };
        return function (t) {
            for (var e = "0123456789abcdef", n = "", o = 0; o < 4 * t.length; o++) n += e.charAt(t[o >> 2] >> o % 4 * 8 + 4 & 15) + e.charAt(t[o >> 2] >> o % 4 * 8 & 15);
            return n;
        }(function (t, e) {
            t[e >> 5] |= 128 << e % 32, t[14 + (e + 64 >>> 9 << 4)] = e;
            for (var c = 1732584193, r = -271733879, l = -1732584194, d = 271733878, h = 0; h < t.length; h += 16) {
                var u = c,
                    g = r,
                    p = l,
                    f = d;
                c = n(c, r, l, d, t[h + 0], 7, -680876936), d = n(d, c, r, l, t[h + 1], 12, -389564586),
                    l = n(l, d, c, r, t[h + 2], 17, 606105819), r = n(r, l, d, c, t[h + 3], 22, -1044525330),
                    c = n(c, r, l, d, t[h + 4], 7, -176418897), d = n(d, c, r, l, t[h + 5], 12, 1200080426),
                    l = n(l, d, c, r, t[h + 6], 17, -1473231341), r = n(r, l, d, c, t[h + 7], 22, -45705983),
                    c = n(c, r, l, d, t[h + 8], 7, 1770035416), d = n(d, c, r, l, t[h + 9], 12, -1958414417),
                    l = n(l, d, c, r, t[h + 10], 17, -42063), r = n(r, l, d, c, t[h + 11], 22, -1990404162),
                    c = n(c, r, l, d, t[h + 12], 7, 1804603682), d = n(d, c, r, l, t[h + 13], 12, -40341101),
                    l = n(l, d, c, r, t[h + 14], 17, -1502002290), r = n(r, l, d, c, t[h + 15], 22, 1236535329),
                    c = o(c, r, l, d, t[h + 1], 5, -165796510), d = o(d, c, r, l, t[h + 6], 9, -1069501632),
                    l = o(l, d, c, r, t[h + 11], 14, 643717713), r = o(r, l, d, c, t[h + 0], 20, -373897302),
                    c = o(c, r, l, d, t[h + 5], 5, -701558691), d = o(d, c, r, l, t[h + 10], 9, 38016083),
                    l = o(l, d, c, r, t[h + 15], 14, -660478335), r = o(r, l, d, c, t[h + 4], 20, -405537848),
                    c = o(c, r, l, d, t[h + 9], 5, 568446438), d = o(d, c, r, l, t[h + 14], 9, -1019803690),
                    l = o(l, d, c, r, t[h + 3], 14, -187363961), r = o(r, l, d, c, t[h + 8], 20, 1163531501),
                    c = o(c, r, l, d, t[h + 13], 5, -1444681467), d = o(d, c, r, l, t[h + 2], 9, -51403784),
                    l = o(l, d, c, r, t[h + 7], 14, 1735328473), r = o(r, l, d, c, t[h + 12], 20, -1926607734),
                    c = i(c, r, l, d, t[h + 5], 4, -378558), d = i(d, c, r, l, t[h + 8], 11, -2022574463),
                    l = i(l, d, c, r, t[h + 11], 16, 1839030562), r = i(r, l, d, c, t[h + 14], 23, -35309556),
                    c = i(c, r, l, d, t[h + 1], 4, -1530992060), d = i(d, c, r, l, t[h + 4], 11, 1272893353),
                    l = i(l, d, c, r, t[h + 7], 16, -155497632), r = i(r, l, d, c, t[h + 10], 23, -1094730640),
                    c = i(c, r, l, d, t[h + 13], 4, 681279174), d = i(d, c, r, l, t[h + 0], 11, -358537222),
                    l = i(l, d, c, r, t[h + 3], 16, -722521979), r = i(r, l, d, c, t[h + 6], 23, 76029189),
                    c = i(c, r, l, d, t[h + 9], 4, -640364487), d = i(d, c, r, l, t[h + 12], 11, -421815835),
                    l = i(l, d, c, r, t[h + 15], 16, 530742520), r = i(r, l, d, c, t[h + 2], 23, -995338651),
                    c = a(c, r, l, d, t[h + 0], 6, -198630844), d = a(d, c, r, l, t[h + 7], 10, 1126891415),
                    l = a(l, d, c, r, t[h + 14], 15, -1416354905), r = a(r, l, d, c, t[h + 5], 21, -57434055),
                    c = a(c, r, l, d, t[h + 12], 6, 1700485571), d = a(d, c, r, l, t[h + 3], 10, -1894986606),
                    l = a(l, d, c, r, t[h + 10], 15, -1051523), r = a(r, l, d, c, t[h + 1], 21, -2054922799),
                    c = a(c, r, l, d, t[h + 8], 6, 1873313359), d = a(d, c, r, l, t[h + 15], 10, -30611744),
                    l = a(l, d, c, r, t[h + 6], 15, -1560198380), r = a(r, l, d, c, t[h + 13], 21, 1309151649),
                    c = a(c, r, l, d, t[h + 4], 6, -145523070), d = a(d, c, r, l, t[h + 11], 10, -1120210379),
                    l = a(l, d, c, r, t[h + 2], 15, 718787259), r = a(r, l, d, c, t[h + 9], 21, -343485551),
                    c = s(c, u), r = s(r, g), l = s(l, p), d = s(d, f);
            }
            return Array(c, r, l, d);
        }(function (t) {
            for (var e = Array(), n = 0; n < 8 * t.length; n += 8) e[n >> 5] |= (255 & t.charCodeAt(n / 8)) << n % 32;
            return e;
        }(t), 8 * t.length));
    },
    DateStr: function () {
        var t = new Date(),
            e = t.getFullYear(),
            n = t.getMonth() + 1,
            o = t.getDate();
        return n < 10 && (n = "0" + n), o < 10 && (o = "0" + o), e + "" + n + o;
    }
}